//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2009-01-01
// Contains ...
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using JetBrains.Annotations;
using LargoCommon.Abstract;
using LargoCommon.Support;
namespace LargoCommon.Music
{
/// Musical material.
/// Musical class.
//// [Serializable]
[ContractVerification(false)]
public sealed class OrchestraBlock {
#region Constructors
///
/// Initializes a new instance of the OrchestraBlock class.
///
/// The given header.
/// The given bar number.
/// The given strip.
public OrchestraBlock(MusicalHeader givenHeader, int givenBarNumber, OrchestraStrip givenStrip)
: this() {
this.Header = givenHeader;
this.BarNumberFrom = givenBarNumber;
this.Strip = givenStrip;
this.DetermineProperties();
//// this.DetermineOrchestraGroup();
}
///
/// Initializes a new instance of the class.
///
/// The mark orchestra block.
public OrchestraBlock(XElement markOrchestraBlock) : this() {
Contract.Requires(markOrchestraBlock != null);
if (markOrchestraBlock == null) {
return;
}
XElement xheader = markOrchestraBlock.Element("Header");
this.Header = new MusicalHeader(xheader);
this.BarNumberFrom = XmlSupport.ReadIntegerAttribute(markOrchestraBlock.Attribute("BarNumberFrom"));
this.BarNumberTo = XmlSupport.ReadIntegerAttribute(markOrchestraBlock.Attribute("BarNumberTo"));
this.NumberOfVocals = XmlSupport.ReadByteAttribute(markOrchestraBlock.Attribute("NumberOfVocals"));
this.NumberOfStrings = XmlSupport.ReadByteAttribute(markOrchestraBlock.Attribute("NumberOfStrings"));
this.NumberOfWoodwinds = XmlSupport.ReadByteAttribute(markOrchestraBlock.Attribute("NumberOfWoodwinds"));
this.NumberOfKeyboards = XmlSupport.ReadByteAttribute(markOrchestraBlock.Attribute("NumberOfKeyboards"));
this.NumberOfBrass = XmlSupport.ReadByteAttribute(markOrchestraBlock.Attribute("NumberOfBrass"));
this.NumberOfGuitars = XmlSupport.ReadByteAttribute(markOrchestraBlock.Attribute("NumberOfGuitars"));
this.NumberOfSynthetic = XmlSupport.ReadByteAttribute(markOrchestraBlock.Attribute("NumberOfSynthetic"));
var xElement = markOrchestraBlock.Element("Lines");
if (xElement != null) {
var xtracks = xElement.Elements("Track");
foreach (var xtrack in xtracks) {
OrchestraTrack track = new OrchestraTrack(xtrack);
this.Strip.OrchestraTracks.Add(track);
}
this.Strip.RecomputeProperties();
}
}
///
/// Initializes a new instance of the OrchestraBlock class.
///
public OrchestraBlock() {
this.Strip = new OrchestraStrip();
}
#endregion
#region Properties - Xml
/// Gets Xml representation.
/// Property description.
public XElement GetXElement {
get {
XElement xmblock = new XElement(
"Block",
new XAttribute("BarNumberFrom", this.BarNumberFrom),
new XAttribute("BarNumberTo", this.BarNumberTo),
new XAttribute("TrackCount", this.TrackCount),
new XAttribute("NumberOfVocals", this.NumberOfVocals),
new XAttribute("NumberOfStrings", this.NumberOfStrings),
new XAttribute("NumberOfWoodwinds", this.NumberOfWoodwinds),
new XAttribute("NumberOfKeyboards", this.NumberOfKeyboards),
new XAttribute("NumberOfBrass", this.NumberOfBrass),
new XAttribute("NumberOfGuitars", this.NumberOfGuitars),
new XAttribute("NumberOfSynthetic", this.NumberOfSynthetic));
var xheader = this.Header.GetXElement;
xmblock.Add(xheader);
//// Lines
XElement xtracks = new XElement("Lines");
foreach (OrchestraTrack track in this.Strip.OrchestraTracks.Where(track => track != null)) {
//// mtrack.MusicalBlock = givenMusicalBlock;
var xtrack = track.GetXElement;
xtracks.Add(xtrack);
}
xmblock.Add(xtracks);
return xmblock;
}
}
#endregion
#region Public properties
///
/// Gets or sets the header.
///
///
/// The header.
///
public MusicalHeader Header { get; set; }
///
/// Gets the name.
///
///
/// The name.
///
public string Name => this.Header.Name;
///
/// Gets or sets the name of the file.
///
///
/// The name of the file.
///
public string FileName => this.Header.FileName;
///
/// Gets or sets the bar number from.
///
///
/// The bar number from.
///
public int BarNumberFrom { get; set; }
///
/// Gets or sets the bar number to.
///
///
/// The bar number to.
///
public int BarNumberTo { get; set; }
///
/// Gets or sets the orchestra strip.
///
///
/// The orchestra strip.
///
public OrchestraStrip Strip { get; set; }
///
/// Gets the name.
///
///
/// The bar number.
///
[UsedImplicitly]
public string Description {
get {
var description = string.Format(CultureInfo.InvariantCulture, "Bar {0,4}-{1,4}", this.BarNumberFrom, this.BarNumberTo);
return description;
}
}
///
/// Gets the section outline.
///
/// Property description.
[UsedImplicitly]
public string OrchestraOutline => this.OrchestraGroup.ToString();
///
/// Gets the section outline.
///
/// Property description.
[UsedImplicitly]
public string SectionOutline {
get {
var s = new StringBuilder();
if (this.NumberOfStrings > 0) {
s.Append("Strings,");
}
if (this.NumberOfWoodwinds > 0) {
s.Append("Woodwinds,");
}
if (this.NumberOfBrass > 0) {
s.Append("Brass,");
}
if (this.NumberOfGuitars > 0) {
s.Append("Guitars,");
}
if (this.NumberOfKeyboards > 0) {
s.Append("Keyboards,");
}
if (this.NumberOfSynthetic > 0) {
s.Append("Synthetic,");
}
var outline = s.ToString();
if (outline.Length > 1) {
outline = outline.Substring(0, outline.Length - 1);
}
return outline;
}
}
///
/// Gets the voice count.
///
///
/// The voice count.
///
public int TrackCount {
get
{
if (this.Strip == null) {
return 0;
}
return this.Strip.OrchestraTracks.Count;
}
}
///
/// Gets the melodic track count.
///
///
/// The melodic track count.
///
public int MelodicTrackCount {
get {
if (this.Strip == null) {
return 0;
}
return this.Strip.MelodicOrchestraTracks.Count;
}
}
///
/// Gets the rhythmic track count.
///
///
/// The rhythmic track count.
///
public int RhythmicTrackCount {
get {
if (this.Strip == null) {
return 0;
}
return this.Strip.RhythmicOrchestraTracks.Count;
}
}
///
/// Gets the section count.
///
///
/// The section count.
///
public int SectionCount
{
get
{
if (this.Strip == null) {
return 0;
}
return this.Strip.SectionCount;
}
}
///
/// Gets the instrument count.
///
///
/// The instrument count.
///
public int InstrumentCount
{
get
{
if (this.Strip == null) {
return 0;
}
return this.Strip.InstrumentCount;
}
}
///
/// Gets or sets the instrument group.
///
/// Property description.
public OrchestraGroup OrchestraGroup { get; set; }
#endregion
#region Private properties
///
/// Gets or sets a value indicating whether [number of strings].
///
///
/// true if [number of strings]; otherwise, false.
///
public byte NumberOfStrings { get; set; }
///
/// Gets or sets a value indicating whether [number of woodwinds].
///
///
/// true if [number of woodwinds]; otherwise, false.
///
public byte NumberOfWoodwinds { get; set; }
///
/// Gets or sets a value indicating whether [number of keyboards].
///
///
/// true if [number of keyboards]; otherwise, false.
///
public byte NumberOfKeyboards { get; set; }
///
/// Gets or sets a value indicating whether [number of brass].
///
///
/// true if [number of brass]; otherwise, false.
///
public byte NumberOfBrass { get; set; }
///
/// Gets or sets a value indicating whether [number of guitars].
///
///
/// true if [number of guitars]; otherwise, false.
///
public byte NumberOfGuitars { get; set; }
///
/// Gets or sets a value indicating whether [number of synthetic].
///
///
/// true if [number of synthetic]; otherwise, false.
///
public byte NumberOfSynthetic { get; set; }
///
/// Gets or sets the number of vocals.
///
/// Property description.
public byte NumberOfVocals { get; set; }
#endregion
#region Public methods
///
/// Determine Instrumentation Class.
///
/// Returns value.
[UsedImplicitly]
private OrchestraGroup DetermineOrchestraGroup() {
var ic = OrchestraGroup.Uniform;
if (this.TrackCount == 1) {
ic = OrchestraGroup.Solo;
}
if (this.NumberOfVocals > 1) {
ic = OrchestraGroup.Choral;
return ic;
}
if (this.NumberOfVocals == 1) {
ic = OrchestraGroup.Vocal;
return ic;
}
//// if (this.HasSynthetic) { ic = OrchestraGroup.Synthetic; }
var n = 0;
if (this.NumberOfStrings > 0) {
n++;
}
if (this.NumberOfWoodwinds > 0) {
n++;
}
if (this.NumberOfBrass > 0) {
n++;
}
if (this.NumberOfGuitars > 0) {
n++;
}
if (this.NumberOfKeyboards > 0) {
n++;
}
if (n > 1) {
ic = this.NumberOfSynthetic > 0 ? OrchestraGroup.ModernGroup : OrchestraGroup.ChamberMusic;
}
if (this.NumberOfStrings > 0 && this.NumberOfWoodwinds > 0 && this.NumberOfBrass > 0) {
ic = this.NumberOfSynthetic > 0 ? OrchestraGroup.ModernOrchestra : OrchestraGroup.ClassicOrchestra;
}
//// ic = InstrumentGroup.Others;
return ic;
}
#endregion
#region Private methods
///
/// Determines the properties.
///
private void DetermineProperties() {
this.NumberOfStrings = 0;
this.NumberOfWoodwinds = 0;
this.NumberOfKeyboards = 0;
this.NumberOfGuitars = 0;
this.NumberOfBrass = 0;
this.NumberOfSynthetic = 0;
this.NumberOfVocals = 0;
var strings = InstrumentsPorter.MelodicInstrumentsOfGroup(InstrumentGroupMelodic.Strings);
var woodwinds = InstrumentsPorter.MelodicInstrumentsOfGroup(InstrumentGroupMelodic.Woodwind);
var keyboards = InstrumentsPorter.MelodicInstrumentsOfGroup(InstrumentGroupMelodic.Keyboards);
var guitars = InstrumentsPorter.MelodicInstrumentsOfGroup(InstrumentGroupMelodic.Guitars);
var brass = InstrumentsPorter.MelodicInstrumentsOfGroup(InstrumentGroupMelodic.Brass);
var synthetics = InstrumentsPorter.MelodicInstrumentsOfGroup(InstrumentGroupMelodic.Synthetic);
var vocals = InstrumentsPorter.MelodicInstrumentsOfGroup(InstrumentGroupMelodic.Vocal);
foreach (var track in this.Strip.OrchestraTracks) {
var instrument = track.InstrumentNumber;
if (strings.Contains(instrument)) {
this.NumberOfStrings++;
}
if (woodwinds.Contains(instrument)) {
this.NumberOfWoodwinds++;
}
if (keyboards.Contains(instrument)) {
this.NumberOfKeyboards++;
}
if (guitars.Contains(instrument)) {
this.NumberOfGuitars++;
}
if (brass.Contains(instrument)) {
this.NumberOfBrass++;
}
if (synthetics.Contains(instrument)) {
this.NumberOfSynthetic++;
}
if (vocals.Contains(instrument)) {
this.NumberOfVocals++;
}
}
}
#endregion
}
}